package com.sskj.mine.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.mine.bean.AddressList;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.ui.activity.WalletAddressManagerActivity;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;


public class WalletAddressManagerActivityPresenter extends BasePresenter<WalletAddressManagerActivity> {

    /**
     * 获取钱包列表
     *
     * @return
     */
    public void getWalletList() {
        httpService.getWalletList()
                .execute(new JsonCallBack<HttpData<AddressList>>() {
                    @Override
                    public void onSuccess(Response<HttpData<AddressList>> response) {
                        HttpData<AddressList> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateUI(httpData.getData());
                        }
                    }
                });
    }

    /**
     * 删除钱包地址
     *
     * @param id 钱包地址Id
     * @return
     */
    public void delWalletAddress(String id) {
        httpService.delWalletAddress(id)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {
                            getWalletList();
                        }
                    }
                });
    }
}
